package com.qn.example.service.impl;

import com.qn.example.mapper.UserMapper;
import com.qn.example.pojo.User;
import com.qn.example.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 21276
 * @version 1.0
 * @date 2023/5/17 16:04
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User login(String phone, String code, String verifyCode) {
        //验证用户输入的验证码和推送的验证码是否相同
        if (code.equalsIgnoreCase(verifyCode)) {
            //调用持久层去判断表里面有没有该手机号，如果没有在登录的同时还要进行注册
            User user = userMapper.findByPhone(phone);
            //如果返回的user不为null代表已经注册过，如果返回的user为null则还需要注册
            if (user == null) {
                user = new User();
                user.setPhone(phone);
                user.setStatus(1);
                //调用持久层新增用户数据
                userMapper.save(user);
            }
            return user;
        }
        return null;
    }
}
